package run;

import processing.core.PApplet;
import processing.core.PVector;

public class InflectionDirectionRule implements CollideRule {

	public void executeRule(LineCell c, LineCell collided, Env e, final PApplet p) {
		
		//rotate by t radians
	    DirChanger d = new DirChanger() {
	    	final int time = (int) p.random(25,100);
	    	private int count = 0;
	    	float t = p.random(-0.05F, 0.05F);
	    	
			public void changeDir(PVector dir) {
				if (isActive()) {
					
				    dir.x = dir.x * (float) Math.cos(t) - dir.y * (float) Math.sin(t);
				    dir.y = dir.x * (float) Math.sin(t) + dir.y * (float) Math.cos(t);
				    count++;
				}
			}
			
			public boolean isActive() {
				if (count < time)
					return true;
				else return false;
			}
	    };

		// do this for 100 timesteps
		collided.addDirChanger(d);
		
	}

}
